package com.learn.jdk.caseDemo;

import com.learn.jdk.MyInterface;

import java.util.Arrays;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @author: lipan
 * @date: 2021/5/6 19:45
 */

public class MethodDeduce {


    public static void main(String[] args) {



        //静态方法推断
        Function<String, Integer> fun1 = Integer::parseInt;
        System.out.println(fun1.apply("23"));

        //普通成员方法
        BiFunction<String, String, String[]> fun2 = String::split;
           //第一参数代表实例，非静态方法需要实例调用，第二个才代表真正的方法
        String[] result = fun2.apply("hello,world", ",");
        System.out.println(Arrays.asList(result));


        //实例的方法引用
        String s="hello,world";
        Function<String, String[]> fun3 = s::split;
        Arrays.stream(fun3.apply(",")).forEach(System.out::println);

        //构造函数 (new String() )
        Supplier<String> fun4  = String::new;
        String s1 = fun4.get();

         //相当于 new Stirng("hello moto")
         Function<String,String> fun5 = String::new;
         String s2=fun5.apply("hello moto");
         System.out.println(s1+"\t"+s2);


         //两个参数
        BiFunction<String,String,Person> fun6=Person::new;
        Person person = fun6.apply("001", "张三");

        //三个参数
       ThreeFuction<Person,String,String,String> fun7=Person::new;
        Person person1 = fun7.apply("100", "lisi", "男");
        System.out.println(person);
        System.out.println(person1);
    }

}
